package com.gexin.model.product;

import com.gexin.common.utils.SQLUtils;
import com.gexin.common.utils.StringUtil;
import com.gexin.model.product.base.BaseProductFlowCount;
import com.jfinal.plugin.activerecord.Page;

/**
 * 业务名称:  t_product_flow_count(商品流量)
 */
@SuppressWarnings("serial")
public class ProductFlowCount extends BaseProductFlowCount<ProductFlowCount> {
	public static final ProductFlowCount dao = new ProductFlowCount();

	public Page<ProductFlowCount>  paginateData(ProductFlowCount p, int  pageindex, int pageSize, String begin, String end){
		SQLUtils sql =new SQLUtils(" FROM t_product_flow_count c LEFT JOIN t_products p ON c.product_id = p.id WHERE 1=1 ");
		if(p!=null){
			if(StringUtil.isNotBlank(p.getStr("shop_id"))){
				sql.whereEquals("p.shop_id ", p.getStr("shop_id"));
			}

			if(StringUtil.isNotBlank(p.getStr("product_name"))){
				sql.whereLike("p.product_name ", p.getStr("product_name"));
			}
		}
		if (StringUtil.isNotEmpty(begin)) {
			sql.append(" and c.sum_date >= '"+begin+"'");
		}
		if (StringUtil.isNotEmpty(end)) {
			sql.append(" and c.sum_date <= '"+end+"'");
		}
		sql.append(" group by c.product_id  ORDER BY  c.pv_data DESC ");
		return  paginate(pageindex,pageSize, "SELECT sum(uv_data) as uv_data,sum(pv_data) as pv_data,sum(pay_order) as pay_order, p.product_name  ", sql.toString());
	}
}
